﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;

namespace SampleMVVMLight
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    private RelayCommand _myCommand;

    public RelayCommand MyCommand
    {
      get { return _myCommand ?? (_myCommand = new RelayCommand(ExecuteMyCommand, CanExecuteMyCommand)); }
    }

    public MainWindow()
    {
      InitializeComponent();

      Messenger.Default.Register<object>(this, MessengerTokens.Token1, o => MethodOnMessageReceive());
    }

    public bool CanExecuteMyCommand()
    {
      return true;
    }

    public void ExecuteMyCommand()
    {
      Messenger.Default.Send<object>(this, MessengerTokens.Token1);
    }

    public void MethodOnMessageReceive()
    {
      // Code
    }
  }

  public enum MessengerTokens
  {
    Token1,
    Token2,
  };
}
